//
//  SYZuChengYuanView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2020/2/27.
//  Copyright © 2020年 SanYi. All rights reserved.
//

#import "SYZuChengYuanView.h"
#import "SYTopLabView.h"
#import "SYZuChengYuanTableViewCell.h"
@interface SYZuChengYuanView ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) SYBackTopView *backView;//顶部viwe
@property (strong, nonatomic) SYTopLabView *topLabView;
@property (strong, nonatomic) UITableView *curTableView;//
@property (strong, nonatomic) NSMutableArray *datalistArr;
@property (assign, nonatomic) NSInteger index;;
@property (copy, nonatomic) NSString *packageId;//选择资源包id

//@property (strong, nonatomic) SYJiaoCaiCell ;

@end
@implementation SYZuChengYuanView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
        [self initSubView];
    }
    return self;
}
- (void)initSubView {
    [self addSubview:self.backView];
    [self.backView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(50);
    }];
    [self addSubview:self.topLabView];
    [self.topLabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.backView.mas_bottom);
        make.height.mas_equalTo(45);
    }];
    
    [self addSubview:self.curTableView];
    [self.curTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.topLabView.mas_bottom);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    _datalistArr = [NSMutableArray array];
    
    [_curTableView registerCellWithNIbNames:@[@"SYZuChengYuanTableViewCell"]];
    
}
- (void)requestDataGroupId:(NSString *)groupId packageId:(NSString *)packageId {
    [MBProgressHUD mj_showLoading];
    [SYRequestAPI zy_requestGetGroupPackageClassListGroupId:groupId packageId:packageId success:^(NSArray *arr) {
        [MBProgressHUD mj_hideHUD];
        [self.datalistArr addObjectsFromArray:arr];
        [self.curTableView reloadData];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUD];
    }];
    
}



- (void)requestDataGroupId:(NSString *)groupId {
    [MBProgressHUD mj_showLoading];
    
    [SYRequestAPI zy_requestGetGroupMemberListGroupId:groupId success:^(NSArray *arr) {
        [MBProgressHUD mj_hideHUD];
        [self.datalistArr addObjectsFromArray:arr];
        [self.curTableView reloadData];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUD];
        [MBProgressHUD zr_showError:error.domain];
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return _datalistArr.count;
//    return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SYZuChengYuanTableViewCell *zyxCell = [tableView dequeueReusableCellWithIdentifier:@"SYZuChengYuanTableViewCell" forIndexPath:indexPath];
    NSDictionary *dict = self.datalistArr[indexPath.row];
    zyxCell.mingziLab.text = [dict nilObjectForKey:@"teacherName"];
    zyxCell.jiaruLab.text = [dict nilObjectForKey:@"createDate"];
    NSMutableString *ischargehand = [dict nilObjectForKey:@"isChargehand"];
    zyxCell.shifouzuzhangLab.text = [ischargehand integerValue] == 1?@"是":@"否" ;
    zyxCell.selectionStyle = UITableViewCellSelectionStyleNone;
    return zyxCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //    NSDictionary *dict = self.datalistArr[indexPath.row];
    //    NSString *path = [dict nilObjectForKey:@"path"];//观看地址
    //    NSString *type = [dict nilObjectForKey:@"type"];//类型
    
}
//头部
- (SYBackTopView *)backView {
    if (!_backView) {
        _backView = [[SYBackTopView alloc] initWithTitleName:@"组成员信息" baseView:self];
    }
    return _backView;
}
#pragma mark -
- (SYTopLabView *)topLabView {
    if (!_topLabView) {
        NSArray *xiaoArr = nil;
        CGFloat bili;
        
        xiaoArr = @[@"老师姓名",@"加入时间",@"是否是组长"];
        bili = 0.333333;
        
        
        _topLabView = [[SYTopLabView alloc] initWithDataNameArr:xiaoArr width:bili];
    }
    return _topLabView;
}

- (UITableView *)curTableView {
    if (!_curTableView) {
        _curTableView = [[UITableView alloc] init];
        _curTableView.delegate = self;
        _curTableView.dataSource = self;
        _curTableView.tableFooterView = [UIView new];
        
    }
    return _curTableView;
}

@end
